import NProgress from '@/plugins/nprogress'
import { Router } from 'vue-router'
import useAdmin from '@/store/useAdmin'

export default function (router: Router) {
    router.beforeEach((to, _) => {
        const admin = useAdmin()
        if (to.matched[0].path == '/admin' && !admin.getToken) {
            return { path: '/admin/login' }
        }
        if (to.path == '/admin/login' && admin.getToken) {
            return { path: '/admin' }
        }
        NProgress.start()
    })

    router.afterEach(() => {
        NProgress.done()
    })
}